package com.dragon.mmochat.model.role;

import java.awt.Color;

import com.dragon.mmochat.MmochatConstant;
import com.dragon.mmochat.model.MmochatSerial;
import com.dragon.mmochat.model.battle.MmochatSme;
import com.dragon.mmochat.model.enumType.MmochatObjOwnerState;
import com.dragon.mmochat.model.enumType.MmochatPetStateType;
import com.dragon.mmochat.model.enumType.MmochatSkillType;
import com.dragon.mmochat.model.enumType.MmochatSmeType;
import com.dragon.mmochat.model.skill.MmochatSkill;
import com.dragon.mmochat.service.MmochatBattleService;
import com.dragon.mmochat.service.MmochatChatService;
import com.dragon.mmochat.util.MmochatUtil;
import com.google.gson.reflect.TypeToken;

//宠物
//petId是transient类型的，故在序列化或GSON时不会保存
//deepClone方式不会调用构造函数，从而可能导致petId未初始化，需要特别注意!
//GSON会调用构造函数
public class MmochatPet extends MmochatMonster implements
		Comparable<MmochatPet> {
	private static final long serialVersionUID = -8771010278307753486L;
	private static MmochatSerial serial = new MmochatSerial();
	private transient int petId; // 宠物ID
	private int exp = 0; // 宠物经验
	private int blood_point = 0; // 体力点
	private int attack_point = 0; // 力量点
	private int sprit_point = 0; // 灵力点
	private int speed_point = 0; // 敏捷点
	private int space_point = 0; // 可分配点
	private int curBlood; // 当前血量
	private int curSprit; // 当前灵力
	private int ownerLevelNeed = 0; // 捕捉和携带的人物等级要求
	private boolean hasUsedInPk = false; // 在一场战斗中是否已经出战过
	private boolean isInPk = false;// 战斗中是否为参战状态
	private MmochatObjOwnerState ownerState = MmochatObjOwnerState.未认主; // 是否认主，认主后不可交易，丟弃，回收(自动取消绑定状态)；解除认主需要10天时间；解除后自动进入绑定状态
	private long releaseOwnerStartTime = 0;// 开始解除认主时间
	private Integer borrowFromRoleId = null;// 所有者roleId。当出借时需要设置

	private MmochatPetStateType state = MmochatPetStateType.休息; // 状态

	public MmochatPet() {
		// TODO:空构造仅用于Gson构造
		// 只有当petId为transient时，重赋值才有效；
		// 从数据库读取出的petId需要重新赋值，以免重启后petId重复
		petId = serial.addAndGetSerialId();
	}

	public MmochatPet(int ownerLevelNeed) {
		this.ownerLevelNeed = ownerLevelNeed;
		petId = serial.addAndGetSerialId();
	}

	public void setNewId() {
		petId = serial.addAndGetSerialId();
	}

	public MmochatPet getCloneWithNewId() {
		MmochatPet pet = (MmochatPet) MmochatUtil.deepClone(this,
				new TypeToken<MmochatPet>() {
				}.getType());
		pet.setSme(pet.getSme());
		pet.setSkills(pet.getSkills());
		return pet;
	}

	public MmochatPet getClone() {
		MmochatPet pet = (MmochatPet) MmochatUtil.deepClone(this,
				new TypeToken<MmochatPet>() {
				}.getType());
		pet.setSme(pet.getSme());
		pet.setSkills(pet.getSkills());
		pet.setPetId(petId);
		return pet;
	}

	public int getPetId() {
		return petId;
	}

	public void setPetId(int petId) {
		this.petId = petId;
	}

	public void setExp(int exp) {
		this.exp = exp;
	}

	public int getExp() {
		return exp;
	}

	public int getBlood_point() {
		return blood_point;
	}

	public int getAttack_point() {
		return attack_point;
	}

	public int getSprit_point() {
		return sprit_point;
	}

	public int getSpeed_point() {
		return speed_point;
	}

	public void delBlood_point(int del) {
		blood_point -= del;
	}

	public void delAttack_point(int del) {
		attack_point -= del;
	}

	public void delSprit_point(int del) {
		sprit_point -= del;
	}

	public void delSpeed_point(int del) {
		speed_point -= del;
	}

	public void addSpace_point(int add) {
		space_point += add;
	}

	// 初始化友好切磋状态
	public void initFriendPkState(int battleId) {
		setCurPkBlood(getTotalBlood());
		setCurPkSprit(getTotalSprit());
		setBattleId(battleId);
		getSme().clear();
		if (state == MmochatPetStateType.参战){
			isInPk = true;
		}else{
			isInPk = false;
		}
	}

	public void initLevel(int newLevel) {
		if (newLevel <= 0) {
			newLevel = 0;
		}
		level = newLevel;
		blood_point = newLevel;
		sprit_point = newLevel;
		attack_point = newLevel;
		speed_point = newLevel;
		space_point = newLevel * 4;
		// 根据等级配置技能
		int petLevel = level;
		if (petLevel >= MmochatConstant.monsterSkill1LevelNeed) {
			MmochatSkillType skillType = null;
			switch (getFamily()) {
			case 阐教:
				skillType = MmochatSkillType.雷电交加;
				break;
			case 人教:
				skillType = MmochatSkillType.寒冰利剑;
				break;
			case 截教:
				skillType = MmochatSkillType.焚心蚀骨;
				break;
			default:
				break;
			}
			if (skillType != null) {
				if (getSkills().get(skillType) == null) {
					MmochatSkill skill = new MmochatSkill();
					skill.setType(skillType);
					getSkills().put(skillType, skill);
				}
			}
		}
		if (petLevel >= MmochatConstant.monsterSkill2LevelNeed) {
			MmochatSkillType skillType = null;
			switch (getFamily()) {
			case 阐教:
				skillType = MmochatSkillType.飞云掣电;
				break;
			case 人教:
				skillType = MmochatSkillType.水漫金山;
				break;
			case 截教:
				skillType = MmochatSkillType.毒龙双飞;
				break;
			default:
				break;
			}
			if (skillType != null) {
				if (getSkills().get(skillType) == null) {
					MmochatSkill skill = new MmochatSkill();
					skill.setType(skillType);
					getSkills().put(skillType, skill);
				}
			}
		}
	}

	// 增加经验后,需要自行保存数据库
	public boolean addExp(MmochatPlayer owner, int add) {
		if (level >= owner.getLevel()
				+ MmochatConstant.zeroAwardOfPetLevelMoreThanOwner) {
			// 宠物高于人物zeroAwardOfPetLevelMoreThanOwner级，不再获得经验
			return false;
		}
		if (borrowFromRoleId != null) {
			// 借来的宠物不获得经验
			return false;
		}
		boolean upLevel = false;
		exp += add;
		if (level < MmochatConstant.maxLevel) {
			int uplevelExp = MmochatBattleService.getPetExpNeedToUplevel(level,
					life_turn);
			if (exp >= uplevelExp) {
				// 升级
				exp -= uplevelExp;
				level++;
				blood_point++;
				sprit_point++;
				attack_point++;
				speed_point++;
				space_point += 4;
				curBlood = getTotalBlood();
				curSprit = getTotalSprit();
				upLevel = true;

				// 技能学习
				if (level >= MmochatConstant.monsterSkill1LevelNeed) {
					MmochatSkillType skillType = null;
					switch (family) {
					case 阐教:
						skillType = MmochatSkillType.雷电交加;
						break;
					case 人教:
						skillType = MmochatSkillType.寒冰利剑;
						break;
					case 截教:
						skillType = MmochatSkillType.焚心蚀骨;
						break;
					default:
						break;
					}
					if (skillType != null) {
						if (skills.get(skillType) == null) {
							MmochatSkill skill = new MmochatSkill();
							skill.setType(skillType);
							skills.put(skillType, skill);
							MmochatChatService.sendSystemMsgToPerson(owner,
									"您的" + getName() + "习得了【"
											+ skillType.toString() + "】!");
						}
					}
				}
				if (level >= MmochatConstant.monsterSkill2LevelNeed) {
					MmochatSkillType skillType = null;
					switch (family) {
					case 阐教:
						skillType = MmochatSkillType.飞云掣电;
						break;
					case 人教:
						skillType = MmochatSkillType.水漫金山;
						break;
					case 截教:
						skillType = MmochatSkillType.毒龙双飞;
						break;
					default:
						break;
					}
					if (skillType != null) {
						if (skills.get(skillType) == null) {
							MmochatSkill skill = new MmochatSkill();
							skill.setType(skillType);
							skills.put(skillType, skill);
							MmochatChatService.sendSystemMsgToPerson(owner,
									"您的" + getName() + "习得了【"
											+ skillType.toString() + "】!");
						}
					}
				}
			}
		}
		return upLevel;
	}

	public void setBlood_point(int bloodPoint) {
		blood_point = bloodPoint;
	}

	public void setAttack_point(int attackPoint) {
		attack_point = attackPoint;
	}

	public void setSprit_point(int spritPoint) {
		sprit_point = spritPoint;
	}

	public void setSpeed_point(int speedPoint) {
		speed_point = speedPoint;
	}

	public void initPkState(int battleId, boolean initBlood) {
		if (initBlood) {
			setCurPkBlood(getTotalBlood());
			setCurPkSprit(getTotalSprit());
		} else {
			setCurPkBlood(Math.min(getTotalBlood(), curBlood));
			setCurPkSprit(Math.min(getTotalSprit(), curSprit));
		}
		setBattleId(battleId);
		getSme().clear();
		battleOrders.clear();
		hasUsedInPk = false;
		if (state == MmochatPetStateType.参战){
			isInPk = true;
		}else{
			isInPk = false;
		}
	}

	public void addCurBlood(int addBlood) {
		curBlood += addBlood;
		if (curBlood < 0) {
			curBlood = 0;
		} else if (curBlood > getTotalBlood()) {
			curBlood = getTotalBlood();
		}
	}

	public void addCurSprit(int addSprit) {
		curSprit += addSprit;
		if (curSprit < 0) {
			curSprit = 0;
		} else if (curSprit > getTotalSprit()) {
			curSprit = getTotalSprit();
		}
	}

	public MmochatPetStateType getState() {
		return state;
	}

	public void setState(MmochatPetStateType state) {
		this.state = state;
	}

	@Override
	public int getId() {
		return petId;
	}

	// @Override
	// public String getInfo() {
	// // TODO
	// return getName();
	// }
	//
	// @Override
	// public MmochatObjectType getObjectType() {
	// return MmochatObjectType.宠物;
	// }

	public int getSpace_point() {
		return space_point;
	}

	public void setSpace_point(int spacePoint) {
		space_point = spacePoint;
	}

	public void addDao(int add) {
		dao += add;
	}

	public int getCurBlood() {
		return curBlood;
	}

	public void setCurBlood(int curBlood) {
		this.curBlood = curBlood;
	}

	public int getCurSprit() {
		return curSprit;
	}

	public void setCurSprit(int curSprit) {
		this.curSprit = curSprit;
	}

	public void setASpacePointToBlood(int num) {
		int trueNum = Math.min(num, space_point);
		if (trueNum > 0) {
			space_point -= trueNum;
			blood_point += trueNum;
		}
	}

	public void setASpacePointToAttack(int num) {
		int trueNum = Math.min(num, space_point);
		if (trueNum > 0) {
			space_point -= trueNum;
			attack_point += trueNum;
		}
	}

	public void setASpacePointToSprit(int num) {
		int trueNum = Math.min(num, space_point);
		if (trueNum > 0) {
			space_point -= trueNum;
			sprit_point += trueNum;
		}
	}

	public void setASpacePointToSpeed(int num) {
		int trueNum = Math.min(num, space_point);
		if (trueNum > 0) {
			space_point -= trueNum;
			speed_point += trueNum;
		}
	}

	public boolean isCanRescure() {
		return false;
	}

	public int getOwnerLevelNeed() {
		return ownerLevelNeed;
	}

	public void setOwnerLevelNeed(int ownerLevelNeed) {
		this.ownerLevelNeed = ownerLevelNeed;
	}

	// TODO:以下是战斗属性

	// 气血 = 500 + 等级*350 + 体质*((69+转生次数*9)*气血成长%+1) + 转生次数 * 3600
	public int getTotalBlood() {
		// 强化
		return (int) ((1 + getBloodExtraPercent()) * (500 + level * 350
				+ blood_point
				* ((69 + life_turn * 9) * blood_protential / 100.0 + 1) + life_turn * 3600));
	}

	// 法力 = 150 + 等级*0 + 灵力*10
	public int getTotalSprit() {
		return 150 + 10 * sprit_point;
	}

	// 速度 = 200 + 等级*20 + 敏捷*(20*速度成长%+1)
	public int getSpeed() {
		double speed = 200 + 20 * level + (20 * speed_protential / 100.0 + 1)
				* speed_point;

		// 强化
		speed = speed * (1 + getSpeedExtraPercent());

		// 辅助技能效果
		double addPercent = 0;
		MmochatSme speedSme = sme.get(MmochatSmeType.加速辅助);
		if (speedSme != null && speedSme.getKeepRound() > 0) {
			addPercent += speedSme.getValue();
		}
		speed = speed * (100 + addPercent) / 100;
		return (int) speed;
	}

	// 物伤 = 500 + 等级*50 + 力量*((34+转生次数*3)*物伤成长%+1) + 转生次数 * 1200
	public int getPhysicalAttack() {
		double attack = 500
				+ level
				* 50
				+ attack_point
				* ((34 + life_turn * 3) * physicalAttack_protential / 100.0 + 1)
				+ life_turn * 1200;

		// 强化
		attack = attack * (1 + getPhysicalExtraPercent());

		// 辅助技能效果
		double addPercent = 0;
		MmochatSme attackSme = sme.get(MmochatSmeType.加攻辅助);
		if (attackSme != null && attackSme.getKeepRound() > 0) {
			addPercent += attackSme.getValue();
		}
		attack = attack * (100 + addPercent) / 100;

		return (int) attack;
	}

	// 法伤 = 500 + 等级*50 + 灵力*((34+转生次数*3)*法伤成长%+1) + 转生次数 * 1200
	public int getSpritAttack() {
		double attack = 500 + level * 50 + sprit_point
				* ((34 + life_turn * 3) * magicAttack_protential / 100.0 + 1)
				+ life_turn * 1200;

		// 强化
		attack = attack * (1 + getMagicExtraPercent());

		// 辅助技能效果
		double addPercent = 0;
		MmochatSme attackSme = sme.get(MmochatSmeType.加攻辅助);
		if (attackSme != null && attackSme.getKeepRound() > 0) {
			addPercent += attackSme.getValue();
		}
		attack = attack * (100 + addPercent) / 100;

		return (int) attack;
	}

	// 物防 = 300 + 等级*96 + 体质*((13+转生次数*3)*物防成长%+1) + 转生次数 * 1200
	public int getPhysicalDefend() {
		double defend = 300
				+ level
				* 96
				+ blood_point
				* ((13 + life_turn * 3) * physicalDefend_protential / 100.0 + 1)
				+ life_turn * 1200;
		// 辅助技能效果
		double addPercent = 0;
		MmochatSme attackSme = sme.get(MmochatSmeType.加防辅助);
		if (attackSme != null && attackSme.getKeepRound() > 0) {
			addPercent += attackSme.getValue();
		}
		defend = defend * (100 + addPercent) / 100;

		return (int) defend;
	}

	// 法防 = 300 + 等级*96 + 体质*((13+转生次数*3)*法防成长%+1) + 转生次数 * 1200
	public int getMagicDefend() {
		double defend = 300 + level * 96 + blood_point
				* ((13 + life_turn * 3) * magicDefend_protential / 100.0 + 1)
				+ life_turn * 1200;

		// 辅助技能效果
		double addPercent = 0;
		MmochatSme attackSme = sme.get(MmochatSmeType.加防辅助);
		if (attackSme != null && attackSme.getKeepRound() > 0) {
			addPercent += attackSme.getValue();
		}
		defend = defend * (100 + addPercent) / 100;

		return (int) defend;
	}

	public int getPhysicalDeadlyAttack() {
		return physicalDeadlyAttack;
	}

	public void setPhysicalDeadlyAttack(int physicalDeadlyAttack) {
		this.physicalDeadlyAttack = physicalDeadlyAttack;
	}

	public int getPhysicalDeadlyAttackDefend() {
		return physicalDeadlyAttackDefend;
	}

	public void setPhysicalDeadlyAttackDefend(int physicalDeadlyAttackDefend) {
		this.physicalDeadlyAttackDefend = physicalDeadlyAttackDefend;
	}

	public int getMagicDeadlyAttack() {
		return magicDeadlyAttack;
	}

	public void setMagicDeadlyAttack(int magicDeadlyAttack) {
		this.magicDeadlyAttack = magicDeadlyAttack;
	}

	public int getMagicDeadlyAttackDefend() {
		return magicDeadlyAttackDefend;
	}

	public void setMagicDeadlyAttackDefend(int magicDeadlyAttackDefend) {
		this.magicDeadlyAttackDefend = magicDeadlyAttackDefend;
	}

	public int getPhysicalDoubleAttack() {
		return physicalDoubleAttack;
	}

	public void setPhysicalDoubleAttack(int physicalDoubleAttack) {
		this.physicalDoubleAttack = physicalDoubleAttack;
	}

	public int getPhysicalDoubleAttackDefend() {
		return physicalDoubleAttackDefend;
	}

	public void setPhysicalDoubleAttackDefend(int physicalDoubleAttackDefend) {
		this.physicalDoubleAttackDefend = physicalDoubleAttackDefend;
	}

	public int getMagicDoubleAttack() {
		return magicDoubleAttack;
	}

	public void setMagicDoubleAttack(int magicDoubleAttack) {
		this.magicDoubleAttack = magicDoubleAttack;
	}

	public int getMagicDoubleAttackDefend() {
		return magicDoubleAttackDefend;
	}

	public void setMagicDoubleAttackDefend(int magicDoubleAttackDefend) {
		this.magicDoubleAttackDefend = magicDoubleAttackDefend;
	}

	public int getPhysicalDefendIgnore() {
		return physicalDefendIgnore;
	}

	public void setPhysicalDefendIgnore(int physicalDefendIgnore) {
		this.physicalDefendIgnore = physicalDefendIgnore;
	}

	public int getMagicDefendIgnore() {
		return magicDefendIgnore;
	}

	public void setMagicDefendIgnore(int magicDefendIgnore) {
		this.magicDefendIgnore = magicDefendIgnore;
	}

	// 物闪 = 5
	public int getPhysicalAvoid() {
		return physicalAvoid;
	}

	// 法闪 = 5
	public int getMagicAvoid() {
		return magicAvoid;
	}

	public int getAntiConfuse() {
		return antiConfuse;
	}

	public void setAntiConfuse(int antiConfuse) {
		this.antiConfuse = antiConfuse;
	}

	public int getAntiFreeze() {
		return antiFreeze;
	}

	public void setAntiFreeze(int antiFreeze) {
		this.antiFreeze = antiFreeze;
	}

	public int getAntiSeal() {
		return antiSeal;
	}

	public void setAntiSeal(int antiSeal) {
		this.antiSeal = antiSeal;
	}

	public int getIgnoreAntiConfuse() {
		return ignoreAntiConfuse;
	}

	public void setIgnoreAntiConfuse(int ignoreAntiConfuse) {
		this.ignoreAntiConfuse = ignoreAntiConfuse;
	}

	public int getIgnoreAntiFreeze() {
		return ignoreAntiFreeze;
	}

	public void setIgnoreAntiFreeze(int ignoreAntiFreeze) {
		this.ignoreAntiFreeze = ignoreAntiFreeze;
	}

	public int getIgnoreAntiSeal() {
		return ignoreAntiSeal;
	}

	public void setIgnoreAntiSeal(int ignoreAntiSeal) {
		this.ignoreAntiSeal = ignoreAntiSeal;
	}

	public int getStrengthenConfuse() {
		return strengthenConfuse;
	}

	public void setStrengthenConfuse(int strengthenConfuse) {
		this.strengthenConfuse = strengthenConfuse;
	}

	public int getStrengthenFreeze() {
		return strengthenFreeze;
	}

	public void setStrengthenFreeze(int strengthenFreeze) {
		this.strengthenFreeze = strengthenFreeze;
	}

	public int getStrengthenSeal() {
		return strengthenSeal;
	}

	public void setStrengthenSeal(int strengthenSeal) {
		this.strengthenSeal = strengthenSeal;
	}

	public int getPhysicalDefendPercent() {
		return physicalDefendPercent;
	}

	public void setPhysicalDefendPercent(int physicalDefendPercent) {
		this.physicalDefendPercent = physicalDefendPercent;
	}

	public int getMagicDefendPercent() {
		return magicDefendPercent;
	}

	public void setMagicDefendPercent(int magicDefendPercent) {
		this.magicDefendPercent = magicDefendPercent;
	}

	public int getAntiGodSkill() {
		return antiGodSkill;
	}

	public void setAntiGodSkill(int antiGodSkill) {
		this.antiGodSkill = antiGodSkill;
	}

	public int getAntiHumanSkill() {
		return antiHumanSkill;
	}

	public void setAntiHumanSkill(int antiHumanSkill) {
		this.antiHumanSkill = antiHumanSkill;
	}

	public int getAntiDevilSkill() {
		return antiDevilSkill;
	}

	public void setAntiDevilSkill(int antiDevilSkill) {
		this.antiDevilSkill = antiDevilSkill;
	}

	public int getIgnoreAntiGodSkill() {
		return ignoreAntiGodSkill;
	}

	public void setIgnoreAntiGodSkill(int ignoreAntiGodSkill) {
		this.ignoreAntiGodSkill = ignoreAntiGodSkill;
	}

	public int getIgnoreAntiHumanSkill() {
		return ignoreAntiHumanSkill;
	}

	public void setIgnoreAntiHumanSkill(int ignoreAntiHumanSkill) {
		this.ignoreAntiHumanSkill = ignoreAntiHumanSkill;
	}

	public int getIgnoreAntiDevilSkill() {
		return ignoreAntiDevilSkill;
	}

	public void setIgnoreAntiDevilSkill(int ignoreAntiDevilSkill) {
		this.ignoreAntiDevilSkill = ignoreAntiDevilSkill;
	}

	public int getSuperPhysicalAttack() {
		return superPhysicalAttack;
	}

	public void setSuperPhysicalAttack(int superPhysicalAttack) {
		this.superPhysicalAttack = superPhysicalAttack;
	}

	public int getSuperSpritAttack() {
		return superSpritAttack;
	}

	public void setSuperSpritAttack(int superSpritAttack) {
		this.superSpritAttack = superSpritAttack;
	}

	public boolean isDisappearWhenDie() {
		return true;
	}

	public boolean isHasUsedInPk() {
		return hasUsedInPk;
	}

	public void setHasUsedInPk(boolean hasUsedInPk) {
		this.hasUsedInPk = hasUsedInPk;
	}

	// 网页上显示的宠物信息
	public String getPetInfoInHtml() {
		String info = "";
		info += ownerState.toString() + "<br/>";
		info += "<b>" + getPetTypeName() + "(" + level + "级)&nbsp;&nbsp;"
				+ state.toString() + "</b><br/>";
		info += "转生次数:" + life_turn + "次<br/>";
		info += "气血：" + getTotalBlood() + "&nbsp;&nbsp;" + "法力："
				+ getTotalSprit() + "<br/>" + "物伤：" + getPhysicalAttack()
				+ "&nbsp;&nbsp;" + "法伤：" + getSpritAttack() + "<br/>" + "速度："
				+ getSpeed() + "&nbsp;&nbsp;" + "武学：" + getDao() + "<br/>";
		info += "成长："
				+ (blood_protential + physicalAttack_protential
						+ magicAttack_protential + speed_protential
						+ physicalDefend_protential + magicDefend_protential)
				+ "<br/>";
		info += "血量成长：" + blood_protential + "&nbsp;&nbsp;" + "物攻成长："
				+ physicalAttack_protential + "<br/>" + "法攻成长："
				+ magicAttack_protential + "&nbsp;&nbsp;" + "速度成长："
				+ speed_protential + "<br/>" + "物防成长："
				+ physicalDefend_protential + "&nbsp;&nbsp;" + "法防成长："
				+ magicDefend_protential + "<br/>";
		info += "属性：未分配(" + getSpace_point() + ")<br/>";
		info += "力量 " + getAttack_point() + "&nbsp;&nbsp;灵力 "
				+ getSprit_point() + "&nbsp;&nbsp;体力 " + getBlood_point()
				+ "&nbsp;&nbsp;敏捷  " + getSpeed_point() + "<br/>";
		return info;
	}

	// 简易宠物信息
	public String getPetDealInfo() {
		String info = "";
		int level = getLevel();
		int blood_protential = (int) (getBlood_protential() * (1 + getBloodExtraPercent()));
		int physicalAttack_protential = (int) (getPhysicalAttack_protential() * (1 + getPhysicalExtraPercent()));
		int magicAttack_protential = (int) (getMagicAttack_protential() * (1 + getMagicExtraPercent()));
		int speed_protential = (int) (getSpeed_protential() * (1 + getSpeedExtraPercent()));
		int physicalDefend_protential = getPhysicalDefend_protential();
		int magicDefend_protential = getMagicDefend_protential();
		info += MmochatUtil.wrapColor(getPetTypeName() + "(" + level + "级)\n",
				Color.yellow);
		info += MmochatUtil.wrapColor("气血：" + getTotalBlood() + "\n" + "法力："
				+ getTotalSprit() + "\n" + "物伤：" + getPhysicalAttack() + "\n"
				+ "法伤：" + getSpritAttack() + "\n" + "速度：" + getSpeed() + "\n"
				+ "武学：" + getDao() + "\n", Color.white);
		info += MmochatUtil.wrapColor("成长："
				+ (blood_protential + physicalAttack_protential
						+ magicAttack_protential + speed_protential
						+ physicalDefend_protential + magicDefend_protential)
				+ "\n", Color.cyan);
		info += MmochatUtil.wrapColor("血量成长：" + blood_protential + "\n"
				+ "物攻成长：" + physicalAttack_protential + "\n" + "法攻成长："
				+ magicAttack_protential + "\n" + "速度成长：" + speed_protential
				+ "\n" + "物防成长：" + physicalDefend_protential + "\n" + "法防成长："
				+ magicDefend_protential + "\n", Color.green);
		info += MmochatUtil.wrapColor("属性：未分配(" + getSpace_point() + ")\n",
				Color.cyan);
		info += MmochatUtil.wrapColor("力量 " + getAttack_point() + " 灵力 "
				+ getSprit_point() + " 体力 " + getBlood_point() + " 敏捷  "
				+ getSpeed_point() + "\n", Color.green);
		return info;
	}

	@Override
	public int compareTo(MmochatPet other) {
		return other.getLevel() - level;
	}

	public String getPetTypeName() {
		String typeInfo = "";
		if (borrowFromRoleId != null) {
			typeInfo = "借";
		} else if (ownerState == MmochatObjOwnerState.已认主) {
			typeInfo = "认主";
		} else if (ownerState == MmochatObjOwnerState.解除认主中) {
			typeInfo = "解认";
		} else {
			typeInfo = petType.toString();
		}
		if (life_turn > 0) {
			return roleType.toString() + "(" + life_turn + "转" + typeInfo + ")";
		} else {
			return roleType.toString() + "(" + typeInfo + ")";
		}
	}

	public void addLife_turn(int add) {
		life_turn += add;
		life_turn = Math.max(0, life_turn);
		life_turn = Math.min(life_turn, MmochatConstant.maxLifeTurn);
	}

	public MmochatObjOwnerState getOwnerState() {
		return ownerState;
	}

	public void setOwnerState(MmochatObjOwnerState ownerState) {
		this.ownerState = ownerState;
	}

	public long getReleaseOwnerStartTime() {
		return releaseOwnerStartTime;
	}

	public void setReleaseOwnerStartTime(long releaseOwnerStartTime) {
		this.releaseOwnerStartTime = releaseOwnerStartTime;
	}

	public Integer getBorrowFromRoleId() {
		return borrowFromRoleId;
	}

	public void setBorrowFromRoleId(Integer borrowFromRoleId) {
		this.borrowFromRoleId = borrowFromRoleId;
	}

	public String getLevelInfo() {
		String info = "";
		if (life_turn > 0) {
			info += life_turn + "转";
		}
		info += level + "级";
		return info;
	}

	public boolean isInPk() {
		return isInPk;
	}

	public void setInPk(boolean isInPk) {
		this.isInPk = isInPk;
	}

}
